#include <vector>
#include <string>
#include <stack>
using namespace std;
/*
 * @lc app=leetcode.cn id=150 lang=cpp
 *
 * [150] 逆波兰表达式求值
 */

// @lc code=start
class Solution {
public:
    int evalRPN(vector<string>& tokens) {
        stack<string> cal;
        for (int i = 0; i < tokens.size(); i++) {
            if (tokens[i] == "+") {
                string o1 = cal.top(); cal.pop();
                string o2 = cal.top(); cal.pop();
                cal.push(to_string(stoi(o1) + stoi(o2)));
            }
            else if (tokens[i] == "-") {
                string o1 = cal.top(); cal.pop();
                string o2 = cal.top(); cal.pop();
                cal.push(to_string(stoi(o2) - stoi(o1)));
            }
            else if (tokens[i] == "*") {
                string o1 = cal.top(); cal.pop();
                string o2 = cal.top(); cal.pop();
                cal.push(to_string(stoi(o2) * stoi(o1)));
            }
            else if (tokens[i] == "/") {
                string o1 = cal.top(); cal.pop();
                string o2 = cal.top(); cal.pop();
                cal.push(to_string(stoi(o2) / stoi(o1)));
            } else cal.push(tokens[i]);
        }
        return stoi(cal.top());
    }
};
// @lc code=end

